package com.vehicle.domains.vo;

import com.vehicle.enums.StatusCode;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> {
    private String code;
    private String message;
    private T data;

    public Result(StatusCode statusCode) {
        this.code = statusCode.getCode();
        this.message = statusCode.getMessage();
    }

    public static Result<Void> success() {
        return new Result<Void>(StatusCode.SUCCESS);
    }

    public static <T> Result<T> success(T data) {
        Result<T> voidResult = new Result<>(StatusCode.SUCCESS);
        voidResult.setData(data);
        return voidResult;
    }

    public static Result<Void> error(String code, String message) {
        Result<Void> result = new Result<>();
        result.setCode(code);
        result.setMessage(message);
        return result;
    }
}
